#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include<stdlib.h>


//打印一个随机数，rand
//rand（）返回的是伪随机数，是根据默认的种子1生成的，而srand可以初始化种子
//以时间作为起点（时间戳）time函数可以获得时间戳



#include <time.h>

//int main()
//{
//	srand((unsigned int)time(NULL));
//	printf("%d\n", rand()%100+1);//随机值范围是0-100，%100余数是0-99，再+1
//	printf("%d\n", rand());
//	printf("%d\n", rand());
//	printf("%d\n", rand());
//	return 0;
//}



void game()
{
	int count = 8;
	int guess = 0;
	//1.生成随机值
	int r = rand() % 100 + 1;
	//2.猜数字
	while (count)//(1)//死循环
	{
		printf("还有%d机会\n", count);
		printf("请猜数字:>\n");
		scanf("%d", &guess);
		if(guess < r)
			printf("猜小了\n");
		else if(guess > r)
			printf("猜大了\n");
		else
		{
			printf("恭喜你，猜对了！！！\n");
			break;
		}
		count--;
	}
	if (count == 0)
		printf("次数用完，游戏失败\n");
}









int main()
{
	srand((unsigned int)time(NULL));
	int input = 0;
	do
	{
		printf("********************\n");
		printf("*******1.play*******\n");
		printf("*******0.exit*******\n");
		printf("********************\n");
		printf("********************\n");
		printf("********************\n");
		printf("请选择:>\n");
		scanf("%d", &input);//1,0
		switch (input)
		{
		
		case 1:
			game();
			
			break;
		case 0:
			printf("退出游戏\n");
			break;
		default:
			printf("输入错误，请重新选择\n");
			break;

		}

	} while (input);

	return 0;
}
